package cn.jtool.dig.client.comm;

import cn.jtool.dig.common.netty.SessionManager;
import cn.jtool.dig.common.netty.TcpClient;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

public class VirtualManager {



    //***********************三方服务器链路缓存***********************
    private static Map<Long, TcpClient> clientMap = Maps.newConcurrentMap();

    public static List<TcpClient> getClient(){
        return Lists.newArrayList(clientMap.values());
    }

    public static void addClient(TcpClient tcpClient){
        clientMap.put(tcpClient.getChannelId(), tcpClient);
    }
    public static TcpClient getClient(long channelId){
        return clientMap.get(channelId);
    }
    public static void removeClient(long channelId){
        clientMap.remove(channelId);
    }
    public static void close() {
        for (Map.Entry<Long,TcpClient> entry : clientMap.entrySet()){
            TcpClient tcpClient = entry.getValue();
            tcpClient.stop();
        }
        clientMap.clear();
        SessionManager.remove();
    }
}
